package com.trade.data.controller;
import com.trade.data.dto.BacktestDto;
import com.trade.data.dto.PredictInfoDto;
import com.trade.data.manager.CoinMarketManager;
import com.trade.data.dto.CoinMarketDto;
import com.trade.data.dto.common.ApiResponse;
import com.trade.data.manager.PredictManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
public class TestController {
    @Autowired
    CoinMarketManager coinMarketManager;
    @Autowired
    PredictManager predictManager;
    /**
     * 获取币安有合约的所有的usdt交易对
     */
    @GetMapping("/api/getUsdtContracts")
    public ApiResponse<List<String>>getUsdtContracts(){
        return new ApiResponse(true,"success",coinMarketManager.getUsdtContracts());
    }
    /**
     * 获取币安币种k线数据
     * @param symbol
     * @param interval
     * @return
     */
    @GetMapping("/api/quotes")
    public ApiResponse<List<List>> getQuotes(@RequestParam String symbol, @RequestParam String interval,@RequestParam String queryMethod) {
        if(queryMethod.contains("h2")){
            return new ApiResponse(true,"success",coinMarketManager.getH2Quotes(symbol,interval));
        }
        List<List> quotes = coinMarketManager.getBinanceQuotes(symbol, interval);
        return new ApiResponse(true,"success",quotes);
    }

    /**
     * 保存获取的数据
     */
    @PostMapping("/api/saveCoinQuotes")
    public ApiResponse<Void> saveCoinQuotes(@RequestBody CoinMarketDto coinMarketDto){
        coinMarketManager.saveCoinQuotes(coinMarketDto);
        return new ApiResponse(true,"success");
    }


    /**
     * 数据回测
     */
    @PostMapping("/api/backtest")
    public ApiResponse<Void> backtest(@RequestBody BacktestDto backtestDto){
        coinMarketManager.backtest(backtestDto);
        return new ApiResponse(true,"success");
    }

    /**
     * 获取某个时间点的预测结果
     */
    @GetMapping("/api/getPredictResult")
    public ApiResponse<PredictInfoDto> getPredictResult(@RequestParam String coin, @RequestParam String interval ){
        PredictInfoDto predictInfoDto = predictManager.getPredictResult(coin,interval);
        return new ApiResponse(true,"success",predictInfoDto);
    }
}
